package henu.innovation.service.impl;

import henu.innovation.entity.Exam;
import henu.innovation.entity.Student;
import henu.innovation.entity.Teacher;
import henu.innovation.mapper.TeacherMapper;
import henu.innovation.service.TeacherService;
import henu.innovation.utils.ReadExcelUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;
@Service
public class TeacherServicelmpl implements TeacherService {

    @Resource
   private TeacherMapper teacherMapper;

    public void setTeacherMapper(TeacherMapper teacherMapper) {
        this.teacherMapper = teacherMapper;
    }

    @Override
    public Teacher TeacherSignIn(String name, String password) {
        return teacherMapper.TeacherSignIn(name, password);
    }

    @Override
    public Boolean TeacherPasswordChanged(Teacher teacher) {
        return teacherMapper.TeacherPasswordChanged(teacher);
    }

    @Override
    public boolean addTeacher(Teacher teacher) {
        return teacherMapper.addTeacher(teacher);
    }

    @Override
    public boolean deleteTeacherById(int id) {
        return teacherMapper.deleteTeacherById(id);
    }

    @Override
    public List<Teacher> findAllTeachers() {
        return teacherMapper.findAllTeachers();
    }

    @Override
    public boolean updateTeacher(Teacher teacher) {
        return teacherMapper.updateTeacher(teacher);
    }

    @Override
    public Teacher FindTeacherById(int id) {
        return teacherMapper.FindTeacherById(id);
    }

//    @Override
//    public Exam teacherAddExam(String name, String starttime, Boolean autostart) {
//        return teacherMapper.teacherAddExam(name, starttime, autostart);
//    }
    @Override
    public Boolean teacherAddExam(Exam exam){
        return  teacherMapper.teacherAddExam(exam);
    }
    @Override
    public Exam teacherFindExam(int id){
        return teacherMapper.teacherFindExamById(id);
    }

    @Override
    public List<Exam> showAllExamsByCreator(String creator) {
        return teacherMapper.showAllExamsByCreator(creator);
    }

    @Override
    public List<Exam> showAllExams() {
        return teacherMapper.showAllExams();
    }

    @Override
    public boolean deleteExamById(int id){
        return teacherMapper.deleteExamById(id);
    }
    //    @Override
//    public Boolean teacherAddStudent(String number,String name,String clazz){
//        return teacherMapper.teacherAddStudent(number, name, clazz);
//    }
    @Override
    public Boolean teacherAddStudent(Student student){
        return teacherMapper.teacherAddStudent(student);
    }
   //
   @Override
   public boolean excelUpload(String name, MultipartFile file) {
       boolean b = false;
       //创建处理EXCEL
       ReadExcelUtils readExcel=new ReadExcelUtils();
       //解析excel，获取客户信息集合。
       List<Student> studentList= readExcel.getExcelInfo(name, file);


       if(studentList != null){
           b = true;
       }

       //迭代添加客户信息（注：实际上这里也可以直接将customerList集合作为参数，在Mybatis的相应映射文件中使用foreach标签进行批量添加。）

       for(Student student:studentList){
           teacherMapper.teacherAddStudent(student);
       }
       return b;
   }
    //查找学生
    @Override
    public Student teacherFindStudent(String number,String name,String clazz){
        return teacherMapper.teacherFindStudent(number, name, clazz);
    }
    //查找学生通过ip
    @Override
    public Student teacherFindStudentByIp(String ipbinding){
        return teacherMapper.teacherFindStudentByIp(ipbinding);
    }
    //    @Override
//    public Teacher TeacherPasswordChanged(Teacher teacher) {
//        return teacherMapper.TeacherPasswordChanged(teacher);
//    }
}
